(function(){
    "use strict";
    var projectSelectController=function ($scope,$http,$modal,projectstart_Service){

        var productList = JSON.parse(localStorage.getItem("productList"));
        if (productList === null || productList === undefined || productList.length === 0){
            productList = [];
        }
        $scope.list = angular.copy(productList);
        $scope.keyword ="";
        $scope.find = function () {
            if ($scope.keyword === null || $scope.keyword === undefined || $scope.keyword.trim() === ''){
                $scope.keyword = '';
                $scope.list = angular.copy(productList);
            }
            if ($scope.list !== null && $scope.list !== undefined && $scope.list.length > 0){
                var len = $scope.list.length;
                var arr = [];
                var reg = new RegExp($scope.keyword);
                for(var i=0;i<len;i++){
                    //如果字符串中不包含目标字符会返回-1
                    var productName = $scope.list[i].productName
                    if(productName.match(reg)){
                        arr.push($scope.list[i]);
                    }
                }
                $scope.list = [];
                $scope.list = angular.copy(arr);
                return arr;
            }
            // projectstart_Service.findProject({keyword:$scope.keyword}).success(function (data) {
            //     if (data.result.length > 0 ){
            //         $scope.list = data.result;
            //     } else {
            //         $scope.list = [];
            //     }
            // });
        };
        $scope.find();

        $scope.doChange = function(item){
            console.log(item.id);
            window.location.href = "configManage.html?productId="+item.productId;
        };

        $scope.doCreate = function () {
            window.location.href = "configManage.html";
        };
    };

    angular.module("cicd.projectselect",[])
        .controller("ProjectSelectController",["$scope","$http","$modal","projectstart_Service",projectSelectController])

})();
